package cn.com.cfae.iras.doc.analyze.parse;

import cn.com.cfae.iras.doc.analyze.parse.model.TableType;
import cn.com.cfae.iras.doc.analyze.parse.model.table.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 表格体系构造器
 */
public class TableUtil {
    private static final Logger logger = LoggerFactory.getLogger(TableUtil.class);

    private static TableUtil tableUtil = new TableUtil();

    private TableUtil() {
    }

    public static TableUtil getInstance() {
        return tableUtil;
    }

    public BaseTable initTable(TableType tableType) {
        logger.info("开始初始化表格体系，表格类型：{}......", tableType.getName());
        long t1 = System.currentTimeMillis();
        if (tableType == null) {
            throw new RuntimeException("表格类型为空，中断后续分析！！！");
        }
        BaseTable baseTable = null;
        switch (tableType) {
            case M:
                baseTable = new MTable();
                break;
            case BM:
                baseTable = new BMTable();
                break;
            case DM:
                baseTable = new DMTable();
                break;
            case BDM:
                baseTable = new BDMTable();
                break;
        }
        if (baseTable == null) {
            throw new RuntimeException(String.format("未支持的表格类型，实际传入值：%s。", tableType.getName()));
        }
        baseTable.initTable();
        long t2 = System.currentTimeMillis();
        logger.info("初始化表格体系完成，表格类型：{}，表格体系详情：{}，耗时：{}毫秒。", tableType.getName(), GsonUtil.getInstance().toJson(baseTable), (t2 - t1));
        return baseTable;
    }
}
